06. CODE: Write the A* Search Stub

Write the A* Search Stub

In this exercise, you will modify route_planner.h, route_planner.cpp, main.cpp, and render.cpp to add a method AStarSearch, which will eventually become the search from start_node to end_node. In this exercise, you will only implement a basic version that returns a direct path between those two nodes. When you are done with this exercise, running the code should render a map with a direct path between the start and end nodes.

## To complete this exercise:

  1. Add a AStarSearch declaration to the RoutePlanner class in route_planner.h. This method will be called from main.cpp, so it must be a public method. AStarSearch will use the start_node and end_node class variables, and it will modify the m_Model class variable, so it does not need any arguments, and should have void return type.
  2. In route_planner.cpp define the AStarSearch method. The method should do the following:
    1. Set the parent of end_node to the start_node.
    2. Set m_Model.path to the result of calling ConstructFinalPath on end_node.
  3. In main.cpp call AStarSearch on the RoutePlanner object. This should happen just after the RoutePlanner object is defined, but before the Render render{model}.
  4. Also in main.cpp use the GetDistance() method of the RoutePlanner object to print the length of the path.
  5. Uncomment the following lines in the Render::Display method in render.cpp. These lines will include the path in the rendered map:
    // DrawPath(surface);
    // DrawStartPosition(surface);   
    // DrawEndPosition(surface);

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: react
  • Opened files (when workspace is loaded): n/a
  • userCode:

    export CXX=g++-7
    export CXXFLAGS=-std=c++17
    cmake_tests() {
    /usr/local/bin/cmake -DTESTING="AStarStub" "$1"
    }
    export -f cmake_tests

Solution

AStarStub